﻿using System;
using Natural.Attributes;
using Natural.Providers;
using Newtonsoft.Json;

namespace Core.Bussiness.Providers
{
    [Impl(Type = ImplType.Provider, Name = "Serializer", Strategy = "Json", Version = 0, Priority = 1)]
    public class NewtonSoftSerializer : ISerializer
    {
        public T Deserialize<T>(string input)
        {
            return (T)Deserialize(input, typeof(T));
        }
        public object Deserialize(string input, Type targetType)
        {
            return JsonConvert.DeserializeObject(input, targetType);
        }
        public object DeserializeObject(string input)
        {
            return JsonConvert.DeserializeObject(input);
        }
        public string Serialize(object obj)
        {
            return JsonConvert.SerializeObject(obj,Formatting.None,new JsonSerializerSettings() { DateFormatString="yyyy-MM-ddThh:mm:ss",  NullValueHandling = NullValueHandling.Ignore });
        }
    }

}
